/*
 * @Description: 验证登录和注册规则的包
 * @Author: 小雨
 * @Date: 2024-07-04 11:13:41
 * @LastEditTime: 2024-07-05 15:35:00
 * @LastEditors: 小雨
 */

const joi = require('joi');

const username = joi.string().alphanum().min(1).max(10).required();

const password = joi
    .string()
    .pattern(/^[\S]{6,12}$/)
    .required();

//定义规则对象
module.exports.reg_login_schema = {
    body: {
        username,
        password,
    },
};

const id = joi.number().integer().min(1).required();
const email = joi.string().email().required();

module.exports.update_userinfo_schema = {
    //对req.body进行验证
    body: {
        id,
        email,
    },
};

exports.update_password_schema = {
    body: {
        oldPwd: password,
        //新密码不能与旧密码保持一致并且还有password规则  joi.ref一致 joi.not反义  joi.not(joi.ref不一致
        newPwd: joi.not(joi.ref('oldPwd')).concat(password),
    },
};

exports.delete_schema = {
    //url验证id
    params: {
        id,
    },
};
